#!/usr/bin/env python
# encoding: utf-8

class Model(object):
    """
    json 转 实体类
    """
    def __init__(self,json):
        assert type(json) == dict,"The Value of input is not dict"
        # print(json)
        self.attr = json
        for key, value in json.items():
            # print(key,value)
            if isinstance(value,dict):
                setattr(self, key+'_', Model.Dict(value))
                # print self.__dict__
                setattr(self, key, Model(value))
                # print self.__dict__
                # model = Model(value)
            else:
                # print key,value
                setattr(self, key, Model.Value(value))
                # setattr(self, key, Model.Value)

    def __str__(self):
        return str(json)

    class Dict:
        """docstring for Value"""
        def __init__(self, d):
            self.value = d


    class Value:
        """docstring for Value"""
        def __init__(self, v):
            self.value = v  

if __name__ == "__main__":
    json = {'whuifang': {'age': 19, 'name': 'whf'}, 'wshice': {'age': 18, 'name': 'wsc'}}
    model = Model(json)
    print model
    # print model.__dir__()
    # print Model.Value
    # print model.wshice.age.va